@extends("admin.base")
@section("contents")
    <div class="row"  style="font-family: 'UKIJ Ekran'">
        <div class="col-lg-6 m-auto">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-primary table-striped mb-0">
                            <tr>
                                <th>id</th>
                                <th>type_ch</th>
                                <th>type_uy</th>
                                <th>order</th>
                                <th>created_at</th>
                                <th>updated_at</th>
                                <th>操作</th>
                            </tr>
                            @foreach($type as $tp)
                                <tr>
                                    <th>{{$tp->id}}</th>
                                    <th>{{$tp->type_ch}}</th>
                                    <th>{{$tp->type_uy}}</th>
                                    <th>{{$tp->order}}</th>
                                    <th>{{$tp->created_at}}</th>
                                    <th>{{$tp->updated_at}}</th>
                                    <th>
                                        <a href="updatetype?id={{$tp->id}}"><button class="btn btn-outline-primary">修改</button></a>
                                        <button onclick="typedel({{$tp->id}})" class="btn btn-outline-danger">删除
                                        </button>
                                    </th>
                                </tr>
                            @endforeach
                        </table>
                    </div>

                </div>
            </div>
        </div>
        @endsection


        @section("scripts")
            <script>

                function typedel(id) {
                    swal({
                        title: "请确认操作",
                        text: "数据被删掉以后无法恢复",
                        icon: "warning",
                        buttons: ["取消", "删除"],
                    });
                    $.ajax({
                        url: "deletetype",
                        dataType: "json",
                        type: "GET",

                        headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'},
                        data: {"id": id},
                        success: function (req) {
                            if (req.err == 0)
                                swal({
                                    title: "操作成功",
                                    text: req.title,
                                    icon: "success",
                                    button: "知道了",
                                }), setTimeout(function() {
                                    location.reload()
                                }, 1000);
                        },error: function (err){

                        }
                })
                }
            </script>
@endsection
